# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Michał Pałubicki <maln0ir@gmx.com>

_pyname=agate-sql
pkgname=python-$_pyname
pkgver=0.5.9
pkgrel=3
pkgdesc='Adds SQL read/write support to agate'
arch=(any)
url="https://$_pyname.readthedocs.org"
license=(MIT)
_pydeps=(agate
         sqlalchemy
         sphinx_rtd_theme)
depends=(python
         "${_pydeps[@]/#/python-}")
makedepends=(python-setuptools
             python-sphinx)
checkdepends=(python-crate
              python-geojson
              python-pytest)
_archive="$_pyname-$pkgver"
source=("$_archive.tar.gz::https://github.com/wireservice/$_pyname/archive/$pkgver.tar.gz")
sha256sums=('610d6a67b5e6924da72a09d5a9b5eb8aa2f7a66fc986df5bd92605163cb3742f')

build() {
	cd "$_archive"
	python setup.py build
	make -C docs html
	local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
	rm -rvf docs/_build/html/_static
	ln -svf "$site_packages/sphinx_rtd_theme/static" docs/_build/html/_static
}

check() {
	cd "$_archive"
	pytest tests
}

package() {
	cd "$_archive"
	python setup.py install --root="$pkgdir" --optimize=1 --skip-build
	install -dm0755 "$pkgdir/usr/share/doc/"
	cp -rv docs/_build/html "$pkgdir/usr/share/doc/$pkgname"
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" COPYING
}
